package com.yyplatform.admin.platform.init.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.yyplatform.admin.platform.config.controller.SysConfigController;
import com.yyplatform.admin.platform.config.controller.SysConfigSwiperController;
import com.yyplatform.admin.platform.config.controller.SysDictController;
import com.yyplatform.admin.platform.config.controller.SysDictItemController;
import com.yyplatform.admin.platform.file.controller.SysFileController;
import com.yyplatform.admin.platform.role.controller.SysMenuController;
import com.yyplatform.admin.platform.role.model.entity.SysMenuEntity;
import com.yyplatform.admin.platform.role.model.enums.MenuTypeEnum;
import com.yyplatform.admin.platform.role.repository.SysMenuRepository;
import com.yyplatform.admin.platform.role.service.SysMenuService;
import com.yyplatform.admin.platform.schedule.controller.JobController;
import com.yyplatform.admin.platform.schedule.controller.JobLogController;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/11/16 20:42
 */
public class InitMenuData2Config {

    private SysMenuRepository sysMenuRepository;

    private SysMenuService sysMenuService;

    public InitMenuData2Config(SysMenuRepository sysMenuRepository, SysMenuService sysMenuService) {
        this.sysMenuRepository = sysMenuRepository;
        this.sysMenuService = sysMenuService;
    }


    public void init() {
        String name = "配置管理";

        //        SysMenuEntity menu = new SysMenuEntity();
        //        menu.setAlwaysShow(true);
        //        menu.setComponent("Layout");
        //        menu.setEnabled(true);
        //        menu.setIcon("el-icon-Setting");
        //        menu.setKeepAlive(true);
        //        menu.setName(name);
        //        menu.setOrderNum(100);
        //        menu.setParams(Collections.emptyList());
        //        menu.setPermissions("");
        //        menu.setPid(0L);
        //        menu.setRedirect("");
        //        menu.setRemark("");
        //        menu.setRouteName("");
        //        menu.setRoutePath("/config");
        //        menu.setVisible(true);

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(true);
        menu.setComponent("Layout");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Setting");
        menu.setKeepAlive(true);
        menu.setName(name);
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(0L);
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("");
        menu.setRoutePath("/config");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_FOLDER.getValue());

        sysMenuRepository.save(menu);


        test_init_系统工具_配置管理(menu);
        test_init_系统工具_任务管理(menu);
        test_init_系统管理_文件管理(menu);
        test_init_系统工具_轮播图配置(menu);
        test_init_系统工具_菜单管理(menu);
        test_init_系统工具_字典管理(menu);

    }


    //    @Test
    public void test_init_系统工具_菜单管理(SysMenuEntity rootMenu) {
        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/menu/index");
        menu.setEnabled(true);
        menu.setIcon("cascader");
        menu.setKeepAlive(true);
        menu.setName("菜单管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:menu:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("PlatformMenu");
        menu.setRoutePath("platform/menu/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        long id = menu.getId();


        sysMenuService.saveBatchByControllerName(id, SysMenuController.class.getName());
    }


    //    @Test
    public void test_init_系统工具_字典管理(SysMenuEntity rootMenu) {


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/dict/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Notebook");
        menu.setKeepAlive(true);
        menu.setName("字典管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:dict:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("PlatformDict");
        menu.setRoutePath("platform/dict/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        long id = menu.getId();

        List<String> list2 = new ArrayList<>();
        list2.add(SysDictController.class.getName());
        list2.add(SysDictItemController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }


    //    @Test
    public void test_init_系统工具_配置管理(SysMenuEntity rootMenu) {

        long id = 0;

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/config/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Setting");
        menu.setKeepAlive(true);
        menu.setName("配置管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:config:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("Config");
        menu.setRoutePath("platform/config/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysConfigController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }


    public void test_init_系统管理_文件管理(SysMenuEntity rootMenu) {


        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/file/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-FolderOpened");
        menu.setKeepAlive(true);
        menu.setName("文件管理");
        menu.setOrderNum(200);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:file:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("File");
        menu.setRoutePath("platform/file/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        sysMenuService.saveBatchByControllerName(id, SysFileController.class.getName());
    }


    //    @Test
    public void test_init_系统工具_任务管理(SysMenuEntity rootMenu) {


        long id = 0;


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/job/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-AlarmClock");
        menu.setKeepAlive(true);
        menu.setName("任务管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:job:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("Job");
        menu.setRoutePath("platform/job/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(JobController.class.getName());
        list2.add(JobLogController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }


    public void test_init_系统工具_轮播图配置(SysMenuEntity rootMenu) {

        long id = 0;

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/swiper/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-AlarmClock");
        menu.setKeepAlive(true);
        menu.setName("轮播管理");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:swiperConfig:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("Swiper");
        menu.setRoutePath("platform/swiper/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysConfigSwiperController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);

    }


}
